<?php

namespace app\controller\admin;

use app\model\api\GenshinRelics;
use app\model\api\GenshinRole;
use app\model\api\GenshinWeapon;
use laytp\BaseController;
use plugin\ali_oss\service\Oss;
use think\facade\Db;


/**
 * 辅助更改数据
 */
class Auxiliary extends BaseController
{
    public function updateGenShinRole(){
        $list = (new GenshinRole())->field('id,recommend_weapon,recommend_relics')->select()->toArray();
        $weapon_list = (new GenshinWeapon())->column('id','name');
        $relics_list = (new GenshinRelics())->column('id','relics_name');
        $newList = [];
        foreach ($list as $item){
            $recommend_weapon = json_decode($item['recommend_weapon'],true);
            $recommend_relics = json_decode($item['recommend_relics'],true);
            foreach ($recommend_weapon as &$i){
                $i['id'] = $weapon_list[$i['name']];
            }
            foreach ($recommend_relics as &$i){
                foreach ($i as &$detail){
                    $detail['id'] = $relics_list[$detail['set_name']];
                }
            }
            $newList[] =[
                'id'=>$item['id'] ,
                'recommend_weapon'=> json_encode($recommend_weapon , 256),
                'recommend_relics'=> json_encode($recommend_relics , 256),
            ];
        }
        (new GenshinRole())->saveAll($newList);
    }
}